<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      selectionType="single"
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>

    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定 </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">关闭 </el-button>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { isEmpty } from '@/utils/utils';
import { getVehicle, getVehicleList } from '@/api/repair/newEnergyVehicleLifetime/vehicleLifetimeReviewJingxsDuan';

export default {
  name: 'addVin',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getVehicleList,
      fetchParams: { xhrAbort: false },
      columns: this.createTableColumns(),
      selectArr: []
    };
  },

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    tableChangeFun(val) {},
    selectChange(val) {
      this.selectArr = val;
      console.log(val);
    },

    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
        // {
        //   title: '车主编号',
        //   dataIndex: 'ownerNo',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '车主',
        //   dataIndex: 'ownerName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '品牌',
        //   dataIndex: 'brandName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '车系',
        //   dataIndex: 'seriesName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '车型',
        //   dataIndex: 'modelName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          placeholder: '请输入车牌号...'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入vin...'
        }
      ];
    },

    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    changeHandle(val) {
      // val.bDate=moment(val['bDate']).format('YYYY-MM-DD')
      // val.eDate=moment(val['eDate']).format('YYYY-MM-DD')
      this.fetchParams = Object.assign({}, val);

      console.log(this.fetchParams);
    },

    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    closeDialog() {
      this.$emit('closeVin');
    },
    async submitBtn() {
      if (this.selectArr.length == 0) {
        this.$notify.warning({ title: '提示信息', message: '请您选择vin' });
        return;
      }

      this.$emit('selectArr', this.selectArr);
    }
  }
};
</script>

<style lang="less" scoped>
/*.btnStyle {*/
/*margin-top: 10px;*/
/*}*/
</style>
